--- 模块功能：JSON功能测试.
-- @author Moore
-- @module json.testJson
-- @license MIT
-- @copyright nanmi.cn
-- @release 2019.01.27

require "misc"

-----------------------encode测试------------------------
local reginfo =
{
    PdtName  = "Toilet",
    ConNum   = "000000000000000",
    CmdType  = "1",
    DevNum   = "0000000000",
    StatFlag = "ACK",
}

local hrtinfo =
{
    PdtName  = "Toilet",
    ConNum   = "000000000000000",
    CmdType  = "2",
    DevNum   = "0000000000",
    StatFlag = "ACK",
}

local scrollinfo =
{
    PdtName  = "Toilet",
    ConNum   = "000000000000000",
    CmdType  = "3",
    DevNum   = "0000000000",
    StatFlag = "FIN",
}

local adcalarm =
{
    PdtName  = "Toilet",
    ConNum   = "000000000000000",
    CmdType  = "4",
    DevNum   = "0000000000",
    StatFlag = "ALM",
}

local rollalarm =
{
    PdtName  = "Toilet",
    ConNum   = "000000000000000",
    CmdType  = "5",
    DevNum   = "0000000000",
    StatFlag = "ALM",
}

local tearalarm =
{
    PdtName  = "Toilet",
    ConNum   = "000000000000000",
    CmdType  = "6",
    DevNum   = "0000000000",
    StatFlag = "ALM",
}

sys.taskInit(function()
    local imei_num = ''

    while imei_num == '' do
	    imei_num = misc.getImei()
	    sys.wait(1000)
	end
	reginfo["ConNum"]    = imei_num
	hrtinfo["ConNum"]    = imei_num
	scrollinfo["ConNum"] = imei_num
	adcalarm["ConNum"]   = imei_num
	rollalarm["ConNum"]  = imei_num
	tearalarm["ConNum"]  = imei_num

	jsonreg    = json.encode(reginfo)
    jsonhrt    = json.encode(hrtinfo)
    jsonscroll = json.encode(scrollinfo)
	jsonadcalm = json.encode(adcalarm)
	jsonrollalm = json.encode(rollalarm)
	jsontearalm = json.encode(tearalarm)

end)


log.info("testJson.encode",jsonreg)
log.info("testJson.encode",jsonhrt)
log.info("testJson.encode",jsonscroll)
-----------------------encode测试------------------------


-----------------------decode测试------------------------
--[[{"KEY3":"VALUE3",
     "KEY4":"VALUE4",
     "KEY2":"VALUE2",
     "KEY1":"VALUE1",
     "KEY5":{"KEY5_2":
     "VALU5_2","KEY5_1":"VALU5_1"}},
     "KEY6":[1,2,3]}]]--
--[[local origin = "{\"KEY3\":\"VALUE3\",\"KEY4\":\"VALUE4\",\"KEY2\":\"VALUE2\",\"KEY1\":\"VALUE1\",\"KEY5\":{\"KEY5_2\":\"VALU5_2\",\"KEY5_1\":\"VALU5_1\"},\"KEY6\":[1,2,3]}"
local tjsondata,result,errinfo = json.decode(origin)
if result and type(tjsondata)=="table" then
    log.info("testJson.decode KEY1",tjsondata["KEY1"])
    log.info("testJson.decode KEY2",tjsondata["KEY2"])
    log.info("testJson.decode KEY3",tjsondata["KEY3"])
    log.info("testJson.decode KEY4",tjsondata["KEY4"])
    log.info("testJson.decode KEY5",tjsondata["KEY5"]["KEY5_1"],tjsondata["KEY5"]["KEY5_2"])
    log.info("testJson.decode KEY6",tjsondata["KEY6"][1],tjsondata["KEY6"][2],tjsondata["KEY6"][3])
else
    log.info("testJson.decode error",errinfo)
end
]]--
-----------------------decode测试------------------------
